<template>
    <div class="app-container">
        <el-row :gutter="20">
            <el-col :span="18">
                <el-card>
                    <div slot="header" class="clearfix">
                        <span>学生列表</span>
                    </div>
                    <div class="body">
                        <student-list :studentList="studentList" />
                    </div>
                </el-card>
            </el-col>
            <el-col :span="6">
                <el-card>
                    <div slot="header" class="clearfix">
                        <span>常见操作</span>
                    </div>
                    <div class="body">
                        <el-button type="primary" @click="test"></el-button>
                        <el-button type="primary" @click="startSignLesson">发起签到</el-button>
                    </div>
                </el-card>
            </el-col>
        </el-row>
        <el-row :gutter="20">
            <el-col :span="12">
                <el-card>
                    <div slot="header" class="clearfix">
                        <span>签到记录</span>
                    </div>
                </el-card>
            </el-col>
            <el-col :span="12">
                <el-card>
                    <div slot="header" class="clearfix">
                        <span>问答记录</span>
                    </div>
                </el-card>
            </el-col>
        </el-row>
    </div>
</template>
<script>
import {lessonInfo} from "@/api/feedback/lesson";
import {startSign} from "@/api/feedback/attendance";
import StudentList from "@/components/Lesson/StudentList";
export default {
    name: "teacher",
    components:{StudentList},
    data() {
        return {
            lessonId:undefined,
            studentList:[],
            ws:null,
        }
    },
    created() {
        let lessonId = this.$route.params && this.$route.params.lessonId;
        this.lessonId=lessonId;
        this.init();
    },
    methods:{
        init(){
            lessonInfo(this.lessonId).then((res)=>{
                this.studentList=res.data.studentList;
            }).catch();
        },
        test(){
           
            if(this.studentList[0].showState==1){
                this.studentList[0].showState=-1;
            }else{
                this.studentList[0].showState=1;
            }
        },
        startSignLesson(){
            let data={lessonId:this.lessonId};
            let msg = data;
            msg.type=0;
            this.ws.send(JSON.stringify(msg));
            // startSign(data).then((res)=>{
            //     // this.studentList=res.data.studentList;
            // }).catch();
       },
    },
    mounted() {
        /**
         * 开始链接
         */
        this.ws = new WebSocket("ws://"+process.env.VUE_APP_WS+"/ws/teacher");
        this.ws.onopen = function () {
          
        }
        this.ws.onmessage = (e) => {
            console.log(e)
        },
        this.onclose  = function (e) {
            console.log(e.code + ' ' + e.reason + ' ' + e.wasClean);
        }

    }
    
}
</script>